<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box{
            width: 700px;
            height: 20px;
            border: 1px solid red;
            margin: 50px auto;
            position: relative;
        }
        #box2{
            height: 20px;
            background-color: yellow;
            float: left;
        }
        #num {
            position: absolute;
            transform: translateY(-50%);
            top: 50%;
            left: 5px;
        }
    </style>
</head>
<body>
    <div id="box">
        <div id="box2" style="width: 0px;"></div>
        <span id="num">0%</span>
    </div>
    <script>
      //添加一个定时器
      var res =  setInterval(function(){

        //获取box2的宽度
        var kuanDu = parseInt(box2.style.width);
        console.log(kuanDu)

        //定时器每运行一次，box2的宽度增加6px
        var curKuanDu = (kuanDu + 15) - 0;
        console.log(curKuanDu)

        // 判断box2的宽度 如果到了700px,就等于700px，并关闭定时器
        if(curKuanDu >= 700 ){

            curKuanDu = 700;

            clearInterval(res);
        }

        //把curKuanDu赋值到box2元素上
        box2.style.width = curKuanDu + 'px';

        // 给数字的元素添加left，根据进度条变化
        num.style.left = curKuanDu + 2 + 'px';
        num.innerHTML = ((curKuanDu / 700) * 100).toFixed(2) + '%';
      },200)

    </script>
</body>
</html>